﻿using System.Collections.Generic;

namespace BlueCrest.ConfigManagement.Core.Data
{
    public class ConfigPathTreeEntity
    {
        public int PathId { get; set; }

        public string PathName { get; set; }

        public ConfigPathTreeEntity Parent { get; set; }

        public List<ConfigPathTreeEntity> Children { get; set; }

        public List<ConfigPathEntryEntity> Entries { get; set; }

        public ConfigPathTreeEntity()
        {
            Children = new List<ConfigPathTreeEntity>();
            Entries = new List<ConfigPathEntryEntity>();
        }

        public ConfigPathTreeEntity(int pathId, string pathName, ConfigPathTreeEntity parent = null)
        {
            PathId = pathId;
            PathName = pathName;
            Parent = parent;
            Children = new List<ConfigPathTreeEntity>();
        }

        public void AddChildren(IEnumerable<ConfigPathTreeEntity> children)
        {
            Children.AddRange(children);
        }

        public void AddChild(int pathId, string pathName)
        {
            Children.Add(new ConfigPathTreeEntity(pathId, pathName, this));
        }

        public override string ToString()
        {
            return string.Format("PathId:{0},PathName:{1},ParentId:{2},Children:{3}", PathId, PathName, Parent != null ? Parent.PathId : 0, Children.Count );
        }
    }
}
